rm(list=ls())
library(ggplot2)
library(plyr)
data <- read.csv("results_interaction.csv", sep=";")
data$gov <- ifelse(data$gov=="Opposition", "Opp", "Gov")
data$family <- factor(data$family, levels=c("General", "Left-wing", "Right-wing", "Ecologist/Socialist"))
data$family <- revalue(data$family, c("General"="Model1\nGeneral",  "Left-wing"= "\nLeft-wing", "Right-wing"="Model2\nRight-wing", "Ecologist/Socialist"="\nEcologist/Socialist"))

fig1 <- ggplot(data, aes(x=gov, y=b)) +
  geom_point() +
  geom_errorbar(aes(ymin=low, ymax=up)) + 
  geom_text(aes(gov, b + 1, label=X,group=NULL), data=data) +
  geom_hline(yintercept=0) + 
  facet_grid(.~family) +
  ylim(c(-3.5,3.5)) + 
  ylab("Marginal effect Military Casualties") +
  xlab("") + 
  theme_minimal()

fig1

dummy <- data.frame(family="Model1\nGeneral", Z=2.6)

fig1 + geom_vline(data=dummy, aes(xintercept=Z))
ggsave(plot=last_plot(), file="marginal_effect_casualties.png",dpi=900)

data <- read.csv("appendix_interactioneffects.csv", sep=";")
data$gov <- ifelse(data$gov=="Opposition", "Opp", "Gov")
data$family <- factor(data$family, levels=c("General", "Left-wing", "Right-wing", "Ecologist/Socialist"))
data$family <- revalue(data$family, c("General"="Model1\nGeneral",  "Left-wing"= "\nLeft-wing", "Right-wing"="Model2\nRight-wing", "Ecologist/Socialist"="\nEcologist/Socialist"))

fig2 <- ggplot(data, aes(x=gov, y=b)) +
  geom_point() +
  geom_errorbar(aes(ymin=low, ymax=up)) + 
  geom_text(aes(gov, b + 1, label=star,group=NULL), data=data) +
  geom_hline(yintercept=0) + 
  facet_grid(type~family) +
  ylim(c(-3.5,3.5)) + 
  ylab("Marginal effect Military Casualties") +
  xlab("") + 
  theme_minimal() +
  theme(text = element_text(size=20))

fig2

ggsave(plot=last_plot(), file="marginal_effects_appendix.png",dpi=900, width=10, height=10)
